package org.jimm.app;

import org.jimm.service.Preferences;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;


public class SmileActivity extends Activity implements OnItemSelectedListener {
	private TextView mSelectText;
    public static final String LOG_TAG = "Jimm:SmileActivity";
  //  private org.jimm.service.Preferences prefs;
    final String[] mSmile = {
            ":-)",
            ";-)",
            ":-(",
            ":-P",
            ":-[",
            ":'(",
            ":-]",
            "*hi*",
            "*kissed*",
            "*thumbs_up*",
            "*sorry*"
    };
    
    //TODO read from file
    /*
     * 
     File define = new File(path+"/define.ini");
	 BufferedReader in = new BufferedReader(new FileReader(define));
	 String line = in.readLine();
	 String[] keys = line.split(",");
     */
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.smile);
        
        mSelectText=(TextView)findViewById(R.id.label);
      
        
        
        GridView smilegrid = (GridView) findViewById(R.id.smile);
        smilegrid.setAdapter(new SmileAdapter(this));
        
        smilegrid.setOnItemSelectedListener(this);
        
       
      
        
        smilegrid.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
               // Toast.makeText(SmileActivity.this, "" + position, Toast.LENGTH_SHORT).show();
            	
            	String Smile=mSmile[position];
            	
                mSelectText.setText(Smile);
                Log.i(LOG_TAG, "Selected Smile: " + Smile);             

               if (Preferences.smileSpaceEnabled) {Smile=" "+Smile+" ";};
                              

                Intent intent= getIntent();
                
                intent.putExtra("MessSmile", Smile);
              //  Log.i(LOG_TAG, "smileCode: " + smileCode);
                setResult(RESULT_OK, intent);
                finish();
            }
        });
    }
    public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
    	String Smile=mSmile[position];
    	mSelectText.setText(Smile);
        
    }
	@Override
	public void onNothingSelected(AdapterView<?> paramAdapterView) {
		mSelectText.setText("");
		
	}
	/*
	@Override
	public void onPause() {
		super.onPause();
		 JimmApplication.closeApp();
	}
	*/
}